package com.example.shop.goods.dto;

import com.example.shop.pojo.Goods;
import com.example.shop.pojo.GoodsType;
import com.example.shop.pojo.Merchant;
import com.fasterxml.uuid.Generators;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.time.LocalDateTime;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
public class NewGoodsInfoParam {

    @NotEmpty
    private String goodsName;

    @NotNull
    private GoodsType goodsType;

    @NotNull
    @Size(min = 1,max = 10)
    private List<MultipartFile> goodsDescriptionPicture;

    private MultipartFile goodsVideo;

    @NotNull
    @Size(min = 1)
    @Valid
    private List<GoodsStyleParam> goodsStyleList;

    @NotNull
    private String goodsIntroduction;

    @NotNull
    @Size(min = 1,max = 10)
    private List<MultipartFile> goodsDetailsPicture;

    public Goods toGoods(Merchant merchant){
        Goods goods = new Goods();
        goods.setGoodsId(Generators.timeBasedGenerator().generate().node());
        goods.setMerchantId(merchant.getMerchantId());
        goods.setGoodsName(goodsName);
        goods.setGoodsType(goodsType.name());
        goods.setGoodsIntroduction(goodsIntroduction);
        goods.setShelfState(1);
        goods.setShelfTime(LocalDateTime.now());
        return goods;
    }



}
